<!-- new -->
<script setup>
import { ref, onMounted } from 'vue'
import HomePanel from './HomePanel.vue';
import { getNewsAPI } from '@/apis/home.js';

// 存储新鲜好物的相关数据
let newsList = ref([]);

const getNewList = async () => {
    let res = await getNewsAPI();
    if (res.code == 1) {
        return res.result
    }
};

onMounted(() => {
    getNewList().then((res) => { newsList.value = res });
});
</script>

<template>
    <HomePanel title="新鲜好物" subtitle="新鲜好物 品质靠谱">
      <!-- 下面这些标签体内容会展示在HomePanel子组件中的slot插槽中 -->
        <ul class="goods-list">
            <li v-for="item in newsList" :key="item.id">
                <RouterLink :to="`/detail/${item.id}`">
                    <!-- v-img-lazy 是一个自定义指令，这个自定义指令所在的 img 标签会成为img-lazy下的mounted中的el参数的值，而 item.picture 会成为img-lazy下的mounted中的binding参数的值  -->
                    <img v-img-lazy="item.picture" alt="" />
                    <p class="name">{{ item.name }}</p>
                    <p class="price">&yen;{{ item.price }}</p>
                </RouterLink>
            </li>
        </ul>
    </HomePanel>
</template>


<style scoped lang='scss'>
.goods-list {
    display: flex;
    justify-content: space-between;
    height: 406px;

    li {
        width: 306px;
        height: 406px;

        background: #f0f9f4;
        transition: all .5s;

        &:hover {
            transform: translate3d(0, -3px, 0);
            box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
        }

        img {
            width: 306px;
            height: 306px;
        }

        p {
            font-size: 22px;
            padding-top: 12px;
            text-align: center;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
        }

        .price {
            color: $priceColor;
        }
    }
}
</style>@/apis/homeStore.js